POV-Ray : Newsgroups : povray.advanced-users : How do you rotate an object to face the origin? : Re: How do you rotate an object to face the origin? Server Time
28 Jul 2024 22:22:53 EDT (-0400)
  Re: How do you rotate an object to face the origin?  
From: Chris B
Date: 16 Dec 2003 16:02:34
Message: <3fdf72ea$1@news.povray.org>
"Rich" <SrP### [at] ricoswebcom> wrote in message
news:Xns### [at] 204213191226...
> "Chris B" <c_b### [at] btconnectcom> wrote in
> news:3fdf2f74@news.povray.org:
>
> > If you know the targetLocation before you translate the object and the
> > object is defined at the origin, then you can rotate it before moving
> > it. If you only need to rotate around the Y axis then the angle is the
> > arctan in degrees of z / x. So you can use atan2d():
> >
> > #declare targetLocation = <3,4,5>;
> > #declare targetAngle = atan2d(targetLocation.z,targetLocation.x);
> >
> ... snip ...
> when I use your formula I
> don't get the expected results.  I've output the relevant variable values
> and copied them below.  Only one or two of these objects are actually
> pointing at or nearly at the origin...
>
> #declare rotation = atan2d(z1,x1);
> #object {
>   thing
>   rotate <0,rotation,0>
>   translate <x1,y1,z1>
> }

Hi Rich,

I should have been a bit more verbose with my response.
The targetAngle gives you the horizontal angle between the positive x-axis
and the target position.
Looking at what you want to do you will need to work with 90-targetAngle,
which you actually get if you take the arctan of x / z.
You will then need to compensate for the direction that your object is
pointing in when you defined it, so if it points at -z to start with you
don't need to compensate at all and you can use rotation = atan2d(x1,z1);
If your object points out along +z you will need to add or subtract 180.
e.g. rotation = 180 + atan2d(x1,z1);
If it's +x then add 90, for -x subtract 90 (I think!!).

This is all from memory, so you may need to adjust stuff or if you still
have trouble post a small, but working example so someone can check it out
and correct any errors.

Regards,
Chris.

>
>
> Z:  0.1,  X:  3.5,  Rotation:   1.0
> Z:  1.4,  X:  3.0,  Rotation:  25.0
> ... snip...


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.